package ain.standard;

import util.Vector;
import environment.Pitch;
import environment.player.Player;

public class StandardPassAntibody extends StandardAbstractAntibody
{
private static int ID = 1;
	
	public StandardPassAntibody(Player player, Pitch pitch)
	{
		super(player, pitch);
	}
	
	public void execute()
	{
		// find team mate
		Player teamMate = null;
		for (Player p : pitch.getPlayers())
		{
			if (p.getTeam().equals(player.getTeam()) && player.getID() != p.getID())
			{
				teamMate = p;
			}
		}
		
		Vector direction = Vector.substract(teamMate.getPosition(), player.getPosition());
		direction.normalize();
		direction.multiply(player.getMaxKickImpulse());
		
		player.kick(direction);
	}
	
	protected double distBallRatioValue(double ratio)
	{
		return (ratio <= 2) ? (ratio / 2) : 1;
	}
	
	protected double distBallGoalValue(double zoneNumber)
	{
		if (zoneNumber <= ((1.0/3.0) * 5))
		{
			return 0;
		}
		else if (zoneNumber <= ((2.0 / 3) * 5))
		{
			return (zoneNumber - ((1.0 / 3) * 5)) / ((1.0 / 3) * 5);
		}
		else if (zoneNumber <= 5)
		{
			if ((1 - ((zoneNumber - ((2.0/3) * 5)) / ((1.0/3) * 5))) < 0) return 0;
			return 1 - ((zoneNumber - ((2.0/3) * 5)) / ((1.0/3) * 5));
		}
		
		else return 0;
	}
	
	protected double imprDistBallGoalValue(double zoneNumber)
	{
		if (zoneNumber <= 1 + (4.0/3.0))
		{
			return 0;
		}
		if (zoneNumber <= 1 + (8.0/3.0))
		{
			return (zoneNumber - (1 + (4.0/3.0))) / (4.0/3.0);
		}
		else
		{
			if ((1 - ((zoneNumber - (1 + (8.0/3.0))) / (4.0/3.0))) < 0) return 0;
			return 1 - ((zoneNumber - (1 + (8.0/3.0))) / (4.0/3.0));
		}
	}
	
	protected double distBallPlayerValue(double distance)
	{
		if (distance <= FAR_RADIUS)
		{
			return 1 - (distance / FAR_RADIUS);
		}
		else return 1;
	}
	
	public int getID()
	{
		return ID;
	}
	
	public String toString()
	{
		return "Pass";
	}
}
